package com.vf.admin.client.controller;

import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.service.AppUserService;
import com.vf.admin.common.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;

@RestController
public class ApiUploadController extends ClientBaseController {

    @Autowired
    AppUserService appUserService;

    /**
     * 阿里云OSS上传图片
     * @param files 上传的图片
     */
    @RequestMapping("/upOssImg")
    @ResponseBody
    public Result upOssImage(MultipartFile[] files) {
        try {
            List<Map<String, String>> list = new ArrayList<>();
            Map<String, String> mm = null;

            for(MultipartFile file : files) {
                String ossUrl = appUserService.aliyunOssupload(file);

                mm = new HashMap<>();
                mm.put("name", ossUrl);
                list.add(mm);
            }
            return sucessJSON(list);
        } catch (Exception e) {
            return errorJSON("上传失败");
        }
    }


}
